<template>
	<div class="system-role-container">
		<el-card shadow="hover">
			<div class="system-user-search mb15">
				<el-form :inline="true">
					<!-- <el-form-item label="角色名称">
            <el-input size="default" v-model="tableData.param.roleName" placeholder="请输入角色名称" class="w-50 m-2" clearable/>
          </el-form-item> -->
					<!-- <el-form-item label="筛选">
						<el-tree-select v-model="value" :data="data" filterable />
					</el-form-item> -->
					<Sousuo @customEvent="handleCustomEvent" :urllist="urllist" ref="childRef"> </Sousuo>
					<el-form-item label="ID">
						<el-input v-model="uuid" :placeholder="'请输入ID'" class="w-50 m-2" size="default"
							@input="keywordChangeid()" />
					</el-form-item>
					<!-- <el-form-item label="平台">
						<el-input v-model="tableData.queryParams.titlept" :placeholder="'请输入平台名'" clearable class="w-50 m-2"
							size="default" @input="keywordChangept($event)" />
					</el-form-item> -->
					<el-form-item>
						<!-- <el-button size="default" type="primary" class="ml10" @click="roleList">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button> -->
						<el-button size="default" type="success" class="ml10" @click="onOpenAddRole">
							<el-icon>
								<ele-FolderAdd />
							</el-icon>
							新增会员
						</el-button>
						<el-button size="default" type="primary" class="ml10" @click="Refresh">
							<!-- <el-icon><Refresh /></el-icon> -->
							刷新页面
						</el-button>
					</el-form-item>
				</el-form>
			</div>
			<el-table :data="tableData.data" style="width: 100%">
				<el-table-column fixed prop="id" label="ID" show-overflow-tooltip></el-table-column>
				<el-table-column prop="username" label="会员账号" width="100"></el-table-column>
				<el-table-column prop="Name" label="真实姓名" show-overflow-tooltip></el-table-column>
				<el-table-column prop="level" label="等级" show-overflow-tooltip></el-table-column>
				<el-table-column prop="agentId" label="是否代理" show-overflow-tooltip></el-table-column>
				<el-table-column prop="profit" label="余额" show-overflow-tooltip></el-table-column>
				<el-table-column prop="coin" label="积分余额" show-overflow-tooltip></el-table-column>
				<el-table-column prop="totalMoney" label="累计充值" show-overflow-tooltip></el-table-column>
				<el-table-column prop="status" label="状态" show-overflow-tooltip></el-table-column>
				<el-table-column prop="money" label="游戏余额" show-overflow-tooltip></el-table-column>
				<el-table-column prop="lastLoginIp" label="最后登录IP" show-overflow-tooltip></el-table-column>
				<el-table-column prop="lastLoginTime" label="创建时间" show-overflow-tooltip></el-table-column>
				<el-table-column label="操作" width="300">
					<template #default="scope">
						<el-button size="small" text type="primary"
							@click="onOpenEditRole(scope.row)"><el-icon><ele-EditPen /></el-icon>修改</el-button>
						<!-- <el-button size="small" text type="primary"
							@click="onRowDel(scope.row)"><el-icon><ele-DeleteFilled /></el-icon>删除</el-button> -->
						<el-button size="small" text type="primary"
							@click="Adjusting_Balanceaon(scope.row.id)"><el-icon><ele-EditPen /></el-icon>调整余额</el-button>
						<!-- <el-button size="small" text type="primary"
							@click="onRowDel(scope.row)"><el-icon><ele-DeleteFilled /></el-icon>一件回收</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum"
				v-model:limit="tableData.param.pageSize" @pagination="apiroleList" />
		</el-card>
		<!-- <EditRole ref="editRoleRef" @getRoleList="roleList"/> -->
		<MemberListadd ref="editRoleRef" @getRoleList="apiroleList" :pd="tableData.pdcs" />
		<Adjusting_Balance ref="Adjusting" @getRoleList="apiroleList" :ids="tableData.ids" />
	</div>
</template>
<script lang="ts">
import { toRefs, reactive, onMounted, ref, defineComponent, toRaw } from 'vue';
import MemberListadd from './component/berListadd.vue';
import Adjusting_Balance from './component/Adjusting_balance.vue';
import Sousuo from '/@/components/sousuo/index.vue';
import { apiMemberList } from '/@/api/MemberManagement/MemberList';
// 定义接口来定义对象的类型  
interface TableData {
	id: number;
	username: number;
	level: number;
	realname: string;
	agentId: string;
	profit: number;
	coin: number;
	lastLoginIp: number;
	lastLoginTime: number;
	totalMoney: number;
	status: string;
	money: number;
	uuid: string;
}
interface TableDataState {
	tableData: {
		queryParams: {
			title: string;
			titleid: string;
			titlename: string;
			titlept: string;
			component: string;
			values: string;
		};
		sourceData: Array<sourceDataff>;
		data: Array<TableData>;
		total: number;
		loading: boolean;
		param: {
			userId: string;
			pageNum: number;
			pageSize: number;
		};
		pdcs: number;
		ids: string;
	};
}
interface sourceDataff {
	value: string;
	label: string;
}
export default defineComponent({
	name: 'apiV1SystemRoleList',
	components: { MemberListadd, Adjusting_Balance, Sousuo },
	//总方法
	setup() {
		// const { proxy } = getCurrentInstance() as any;
		const uuid = ref();
		const urllist = '';
		const addRoleRef = ref();
		const editRoleRef = ref();
		const Adjusting = ref();
		const dataScopeRef = ref();
		const value = ref();
		const state = reactive<TableDataState>({
			tableData: {
				queryParams: {
					title: '',
					titleid: '',
					titlename: '',
					titlept: '',
					component: '',
					values: ''
				},
				data: [],
				sourceData: [
					{ value: '0', label: 'ID' },
					{ value: '1', label: '用户名' },
					{ value: '2', label: '平台' },
				],
				total: 0,
				loading: false,
				param: {
					userId: '',
					pageNum: 1,
					pageSize: 10,
				},
				pdcs: 0,
				ids: '',
			},
		});
		const handleCustomEvent = (data: any) => {
			apiroleList(data);
		};
		const roleList = () => {

		}
		const data = ref(state.tableData.sourceData);
		// 初始化表格数据
		const apiinitTableData = () => {
			apiroleList();
		};
		// 初始化表格数据
		const apiroleList = () => {
			apiMemberList(state.tableData.param).then((res: { data: { userList: never[]; total: number } }) => {
				const list = res.data.userList ?? [];
				const data: Array<TableData> = [];
				list.map((item: TableData) => {
					var sta = '';
					var agentId = '';
					if (Number(agentId) > 0) {
						agentId = '是';
					} else {
						agentId = '否';
					}
					if (Number(item.status) == 0) {
						sta = '禁用';
					} else if (Number(item.status) == 1) {
						sta = '正常';
					} else {
						sta = '已删除';
					}
					data.push({
						id: item.id,
						username: item.username,
						level: item.level,
						realname: item.realname,
						agentId: agentId,
						profit: item.profit,
						coin: item.coin,
						lastLoginIp: item.lastLoginIp,
						lastLoginTime: item.lastLoginTime,
						totalMoney: item.totalMoney,
						status: sta,
						money: item.money,
						uuid: item.uuid
					});
				});
				state.tableData.data = data;
				state.tableData.total = res.data.total;
			});
		};

		//文本框搜索
		const keywordChangeid = () => {
			state.tableData.param.userId = uuid.value
			apiroleList();
		};
		// 筛选
		// const filterable = (_value: any) => {
		// 	console.log('执行');
		// 	console.log(state.tableData.queryParams.title);
		// 	// console.log(value)
		// 	//   data.value = [...state.tableData.sourceData].filter((item) => item.label.includes(value))
		// };
		// 打开新增角色弹窗
		const onOpenAddRole = () => {
			state.tableData.pdcs = 0;
			editRoleRef.value.openDialog();
		};
		// 打开修改角色弹窗
		const onOpenEditRole = (row: Object) => {
			// console.log(row)
			state.tableData.pdcs = 1;
			editRoleRef.value.openDialog(toRaw(row));
		};
		// 调整余额
		const Adjusting_Balanceaon = (row: string) => {
			state.tableData.ids = row;
			Adjusting.value.openDialoga();
		};
		// // 删除角色
		// const onRowDel = (row: any) => {
		// 	ElMessageBox.confirm(`此操作将永久删除角色：“${row.name}”，是否继续?`, '提示', {
		// 		confirmButtonText: '确认',
		// 		cancelButtonText: '取消',
		// 		type: 'warning',
		// 	})
		// 		.then(() => {
		// 			deleteRole(row.id).then(() => {
		// 				ElMessage.success('删除成功');
		// 				proxy.$refs['editRoleRef'].resetMenuSession();
		// 				apiroleList();
		// 			});
		// 		})
		// 		.catch(() => {});
		// };
		// 刷新页面
		// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
		// 刷新页面
		const Refresh = () => {
			state.tableData.param.userId = '';
			childRef.value.hello("hello world！")
			apiinitTableData();
		};

		// 分页改变
		const onHandleSizeChange = (val: number) => {
			state.tableData.param.pageSize = val;
		};
		// 分页改变
		const onHandleCurrentChange = (val: number) => {
			state.tableData.param.pageNum = val;
		};
		// 页面加载时
		onMounted(() => {
			apiinitTableData(); //页面进入渲染
		});
		return {
			uuid,
			urllist,
			roleList,
			handleCustomEvent,
			value,
			Adjusting,
			addRoleRef,
			editRoleRef,
			dataScopeRef,
			onOpenAddRole,
			onOpenEditRole,
			onHandleSizeChange,
			onHandleCurrentChange,
			apiroleList,
			Refresh,
			Adjusting_Balanceaon,
			...toRefs(state),
			keywordChangeid,
			data
			
		};
	},
});
</script>
